home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-06-24 | 13.4 KB | 497 lines | [TEXT/MPS ] |
- // Copyright © 1994-95 by Apple Computer, Inc. All rights reserved.
- // UShapes.cp
-
- #ifndef __USHAPES__
- #include "UShapes.h"
- #endif
-
- // MacApp
-
- #ifndef __UFILE__
- #include <UFile.h>
- #endif
-
- #ifndef __USTREAM__
- #include <UStream.h>
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include <UMacAppUtilities.h>
- #endif
-
- #ifndef __UVIEW__
- #include <UView.h>
- #endif
-
- // Toolbox
-
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- // DrawShapes
-
- #ifndef __PATTERNMENU__
- #include "PatternMenu.h"
- #endif
-
- #ifndef __UDRAWSHAPES__
- #include "UDrawShapes.h"
- #endif
-
- //----------------------------------------------------------------------------------------
-
- const short mColor = 7; // the Color menu resource id
-
- const Boolean kUseOutlineFonts = true;
-
- //========================================================================================
- // CLASS TShape
- //========================================================================================
- #undef Inherited
- #define Inherited TObject
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TShape, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TShape Constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TShape::TShape()
- {
- fIdentifier = 0;
- fLocation = gZeroPt;
- fSize = gZeroPt;
- fPattern = 0;
- fOldPattern = 0;
- fColor = gRGBWhite;
- fIsSelected = false;
- fWasSelected = false;
- }
-
- //----------------------------------------------------------------------------------------
- // TShape::IShape
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TShape::IShape(const CRect& itsFrame, short itsID)
- {
- this->IObject();
-
- fLocation = itsFrame[topLeft];
- fSize = itsFrame.GetSize();
-
- fIdentifier = itsID;
- }
-
- //----------------------------------------------------------------------------------------
- // TShape::DoInitialState
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- void TShape::DoInitialState(TShapeView* /*itsView*/)
- {
- fPattern = RandomPattern();
- if (qNeedsColorQD || gConfiguration.hasColorQD)
- {
- // Pick a random color from the Color menu
- MCEntryPtr pMCEntry = GetMCEntry(mColor, abs(Random() % CountMItems(GetMenuHandle(mColor))) + 1);
- fColor = pMCEntry->mctRGB2;
- }
- else
- fColor = gRGBBlack;
- }
-
- //----------------------------------------------------------------------------------------
- // TShape::ReadFrom
- //----------------------------------------------------------------------------------------
- #pragma segment AReadFile
-
- void TShape::ReadFrom(TStream* aStream) // Override
- {
- Inherited::ReadFrom(aStream);
-
- fIdentifier = aStream->ReadInteger();
- fLocation = aStream->ReadPoint();
- fSize = aStream->ReadPoint();
- fPattern = aStream->ReadInteger();
- fOldPattern = aStream->ReadInteger();
- aStream->ReadRGBColor(fColor);
- aStream->ReadRGBColor(fOldColor);
- fIsSelected = aStream->ReadBoolean();
- fWasSelected = aStream->ReadBoolean();
- }
-
- //----------------------------------------------------------------------------------------
- // TShape::WriteTo
- //----------------------------------------------------------------------------------------
- #pragma segment AWriteFile
-
- void TShape::WriteTo(TStream* aStream) // Override
- {
- Inherited::WriteTo(aStream);
-
- aStream->WriteInteger(fIdentifier);
- aStream->WritePoint(fLocation);
- aStream->WritePoint(fSize);
- aStream->WriteInteger(fPattern);
- aStream->WriteInteger(fOldPattern);
- aStream->WriteRGBColor(fColor);
- aStream->WriteRGBColor(fOldColor);
- aStream->WriteBoolean(fIsSelected);
- aStream->WriteBoolean(fWasSelected);
- }
-
- //----------------------------------------------------------------------------------------
- // TShape::Draw
- //----------------------------------------------------------------------------------------
- #pragma segment ANever
-
- void TShape::Draw()
- {
- this->SubClassResponsibility();
- }
-
- //----------------------------------------------------------------------------------------
- // TShape::DrawOutline
- //----------------------------------------------------------------------------------------
- #pragma segment ANever
-
- void TShape::DrawOutline()
- {
- this->SubClassResponsibility();
- }
-
- //----------------------------------------------------------------------------------------
- // TShape::Highlight
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TShape::Highlight(HLState fromHL, HLState toHL, TView* itsView)
- {
- itsView->SetHLPenState(fromHL, toHL);
-
- // Repaint each shape "handle" in the highlight color
- CRect r(-2, -2, 2, 2);
- CRect extent;
- GetFrame(extent);
-
- // left
- OffsetRect(r, extent.left, (extent.top + extent.bottom) / 2);
- PaintRect(r);
-
- // right
- OffsetRect(r, extent.right - extent.left, 0);
- PaintRect(r);
-
- // top
- OffsetRect(r, -(extent.right - extent.left) / 2, extent.top - ((extent.top + extent.bottom) / 2));
- PaintRect(r);
-
- // bottom
- OffsetRect(r, 0, extent.bottom - extent.top);
- PaintRect(r);
- }
-
- //----------------------------------------------------------------------------------------
- // TShape::SetFields
- //----------------------------------------------------------------------------------------
- #pragma segment AClipboard
-
- void TShape::SetFields(short pattern, CRGBColor color, CRect extentRect)
- {
- fPattern = pattern;
- fColor = color;
- SetFrame(extentRect);
- }
-
- //----------------------------------------------------------------------------------------
- // TShape::GetFrame
- //----------------------------------------------------------------------------------------
- #pragma segment ANever
-
- void TShape::GetFrame(CRect& itsFrame)
- {
- itsFrame = CRect(fLocation, fLocation + fSize);
- }
-
- //----------------------------------------------------------------------------------------
- // TShape::SetFrame
- //----------------------------------------------------------------------------------------
- #pragma segment AClipboard
-
- void TShape::SetFrame(const CRect& extentRect)
- {
- fLocation = extentRect[topLeft];
- fSize = extentRect.GetSize();
- }
-
- //----------------------------------------------------------------------------------------
- // TShape::BeInView
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TShape::BeInView(TShapeView* /*itsView*/)
- {
- }
-
- //========================================================================================
- // CLASS TArrowTool
- //========================================================================================
- #undef Inherited
- #define Inherited TShape
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TArrowTool, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TArrowTool Constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TArrowTool::TArrowTool()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TArrowTool::IArrowTool
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TArrowTool::IArrowTool(CRect itsExtent, short itsID)
- {
- this->IShape(itsExtent, itsID);
-
- // Define the arrow bitmap to be drawn in the palette
- fArwBitMap.rowBytes = 2;
- SetRect(&fArwBitMap.bounds, 0, 0, 16, 16);
- fArwBitMap.baseAddr = (Ptr)&qd.arrow.data;
- }
-
- //----------------------------------------------------------------------------------------
- // TArrowTool::Draw
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TArrowTool::Draw()
- {
- CRect r;
- SetRect(r, 14, 12, 30, 28);
- CopyBits(&fArwBitMap, &(qd.thePort->portBits), &(fArwBitMap.bounds), r, srcOr, NULL);
- }
-
- //========================================================================================
- // CLASS TBox
- //========================================================================================
- #undef Inherited
- #define Inherited TShape
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TBox, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TBox Constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TBox::TBox()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TBox::IBox
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TBox::IBox(CRect itsExtent, short itsID)
- {
- this->IShape(itsExtent, itsID);
- }
-
- //----------------------------------------------------------------------------------------
- // TBox::Draw
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TBox::Draw()
- {
- CRect extent;
- GetFrame(extent);
-
- PenNormal();
- if (qNeedsColorQD || gConfiguration.hasColorQD)
- {
- // Get the color of the menu item representing the shape's color
- RGBForeColor(fColor);
- FillRect(extent, &gPat[fPattern]);
- ForeColor(blackColor);
- }
- else
- FillRect(extent, &gPat[fPattern]);
-
- this->DrawOutline();
- }
-
- //----------------------------------------------------------------------------------------
- // TBox::DrawOutline
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TBox::DrawOutline() // Override
- {
- PenSize(1, 1);
- CRect extent;
- GetFrame(extent);
- FrameRect(extent);
- }
-
- //========================================================================================
- // CLASS THeavyBox
- //========================================================================================
- #undef Inherited
- #define Inherited TBox
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(THeavyBox, Inherited);
-
- //----------------------------------------------------------------------------------------
- // THeavyBox Constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- THeavyBox::THeavyBox()
- {
- BlockSet((Ptr)&fFiller[0], sizeof(fFiller), 0);
- }
-
- //----------------------------------------------------------------------------------------
- // THeavyBox::IHeavyBox
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void THeavyBox::IHeavyBox(CRect itsExtent, short itsID)
- {
- this->IBox(itsExtent, itsID);
- }
-
- //----------------------------------------------------------------------------------------
- // THeavyBox::ReadFrom
- //----------------------------------------------------------------------------------------
- #pragma segment AReadFile
-
- void THeavyBox::ReadFrom(TStream* aStream) // Override
- {
- Inherited::ReadFrom(aStream);
- aStream->ReadBytes(&fFiller, sizeof(fFiller));
- }
-
- //----------------------------------------------------------------------------------------
- // THeavyBox::WriteToFile
- //----------------------------------------------------------------------------------------
- #pragma segment AWriteFile
-
- void THeavyBox::WriteTo(TStream* aStream) // Override
- {
- Inherited::WriteTo(aStream);
- aStream->WriteBytes(&fFiller, sizeof(fFiller));
- }
-
- //----------------------------------------------------------------------------------------
- // THeavyBox::Draw
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void THeavyBox::Draw() // Override
- {
- const CStr255 s = "4K";
-
- Inherited::Draw();
-
- PenSize(2, 2);
- CRect extent;
- GetFrame(extent);
- FrameRect(extent);
- PenSize(1, 1);
-
- TextFont(geneva);
- TextFace(normal);
- TextSize(9);
- TextMode(srcOr);
-
- short x = (extent.left + extent.right) / 2;
- CRect r(x - 7, extent.bottom - 14, x + 7, extent.bottom - 4);
- EraseRect(r);
- MADrawString(s, r, teCenter, kUseOutlineFonts);
- }
-
- //========================================================================================
- // CLASS TCircle
- //========================================================================================
- #undef Inherited
- #define Inherited TShape
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TCircle, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TCircle Constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TCircle::TCircle()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TCircle::ICircle
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TCircle::ICircle(CRect itsExtent, short itsID)
- {
- this->IShape(itsExtent, itsID);
- }
-
- //----------------------------------------------------------------------------------------
- // TCircle::Draw
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TCircle::Draw() // Override
- {
- CRect extent;
- GetFrame(extent);
- PenNormal();
- if (qNeedsColorQD || gConfiguration.hasColorQD)
- {
- // Get the color of the menu item representing the shape's color
- RGBForeColor(fColor);
- FillOval(extent, &gPat[fPattern]);
- ForeColor(blackColor);
- }
- else
- FillOval(extent, &gPat[fPattern]);
-
- this->DrawOutline();
- }
-
- //----------------------------------------------------------------------------------------
- // TCircle::DrawOutline
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TCircle::DrawOutline() // Override
- {
- PenSize(1, 1);
- CRect extent;
- GetFrame(extent);
- FrameOval(extent);
- }
-
-